package com.lanlengran.imagemake;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

/**
 * Created by 13924 on 2017/10/13.
 */

public class BitmapUtils {
    public static Bitmap bitmapCompress(String filePath,int maxLength){
        Bitmap bitmap=BitmapFactory.decodeFile(filePath);
        int oldMaxLength=bitmap.getHeight();
        if (bitmap.getWidth()>bitmap.getHeight()){
            oldMaxLength=bitmap.getWidth();
        }

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = oldMaxLength/maxLength;

       Bitmap bm = BitmapFactory.decodeFile(filePath, options);
        Log.i("wechat", "压缩后图片的大小" + (bm.getByteCount() / 1024 / 1024)
                + "M宽度为" + bm.getWidth() + "高度为" + bm.getHeight());
        return bm;
    }
}
